﻿#include "Caelum.h"
#include <GL/GL.h>
#include <cmath>
#include "ModelLoader.h"

#ifdef _WIN32
int APIENTRY wWinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPTSTR    lpCmdLine,
					 int       nCmdShow)
#else
int main(int argc, const char* argv[])
#endif
{
	Caelum::Client cl;

	

	Caelum::RenderWindow wnd;
	wnd.SetRenderMode(Caelum::RENDERMODE_3D);

	try {
		wnd.Initialize(Caelum::WindowParams::BasicGameWindow);
	} catch (Caelum::BaseException e) {
		MessageBox(NULL, e.GetMsg().c_str(), L"Error", MB_OK); 
	}

	Caelum::Image *t;
	try {
		t = new Caelum::Image(L"test.png");
	} catch (Caelum::BaseException e) {
		MessageBox(NULL, e.GetMsg().c_str(), L"Error", MB_OK); 
	}
	
	bool allow = Caelum::Logger::Get().PromptUploadPermission(&wnd);
	if (allow)
		Caelum::Logger::Get().LogMessage(L"User allowed output data upload.", Caelum::LOGLEVEL_INFO);
	else
		Caelum::Logger::Get().LogMessage(L"User did not allow output data upload.", Caelum::LOGLEVEL_INFO);

	std::wcout << L">";

	wnd.Show();

	Caelum::ModelLoader ml;
	try {
		
		ml.LoadModel(L"Cube.obj");
	} catch (Caelum::NotImplementedException e) {
		MessageBox(NULL, e.GetMsg().c_str(), L"Error", MB_OK); 
	}


	glLoadIdentity();
	glTranslatef(0, 0, -6);
	float x;

	while (wnd.ProcessMessages()) {
		wnd.Update(false);
		x = 75.0f + (std::sin((float)GetTickCount()) * 15.0f);
		wnd.SetFieldOfView(x);
		wnd.SetRenderMode(Caelum::RENDERMODE_3D);
		glBegin(GL_QUADS);
			glTexCoord2i(0, 0); glVertex3f(-1, 1, 0.0);
			glTexCoord2i(0, 1); glVertex3f(1, 1, 0.0);
			glTexCoord2i(1, 1); glVertex3f(1, -1, 0.0);
			glTexCoord2i(1, 0); glVertex3f(-1, -1, 0.0);
		glEnd();
		glFlush();
		wnd.SwapBuffers();
	}

	return 0;
}